package com.example.project.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.example.project.enums.DelEnum;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;


@Component
public class AutoFillConfig implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.fillStrategy(metaObject, "createTime", LocalDateTime.now());
        //存储删除状态
        this.fillStrategy(metaObject, "delFlag", DelEnum.UN_DEL.getDel_flag());
        //存放当前 登入的user
        // this.fillStrategy(metaObject,"createBy", SecurityUtils.get());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date()); // 起始版本 3.3.0(推荐)
    }
}
